"""
存放类
"""

from db import db_handler



class BASE:

    @classmethod
    # 查看用户数据
    def select(cls, username):
        obj = db_handler.select_data(cls, username)
        return obj

    # 保存用户数据
    def save(cls):
        db_handler.save_data(cls)

# 管理员类
class Admin(BASE):

    def __init__(self,user, pwd):
        # 要用self.user为了统一规范
        self.user = user
        self.password = pwd

    # 添加学校方法
    def add_school(self, school_name, addr):
        # 调用学校类实例化得到对象
        school_obj = School(school_name, addr)
        school_obj.save()

    # 添加课程方法
    def add_course(self, school_obj, course_name):
        # 调用课程类实例化得到对象
        course_obj = Course(course_name)
        course_obj.save()
        # 获取当前学校对象，并将课程保存到课程列表中
        school_obj.course_list.append(course_name)
        # 更新学校数据
        school_obj.save()


    # 添加讲师方法
    def add_teacher(self, teacher_name, teacher_pwd):
        # 调用讲师类实例化得到对象
        teacher_obj = Teacher(teacher_name, teacher_pwd)
        teacher_obj.save()


# 学校类
class School(BASE):

    def __init__(self, name, addr):
        self.user = name
        self.addr = addr
        self.course_list = []



# 课程类
class Course(BASE):

    def __init__(self, course_name):
        self.user = course_name

# 老师类
class Teacher(BASE):

    def __init__(self, teacher_name, teacher_pwd):
        self.user = teacher_name
        self.password = teacher_pwd

# 学生类
class Student(BASE):

    def __init__(self, user, pwd):
        self.user = user
        self.password = pwd
        # 每个学生只能有一个校区
        self.school = None
        # 一个学生可以选择多门课
        self.course_list = []
        # 学生课程分数
        self.score_dict = {}  # {"course_name": 0}

    # 学生添加学校方法
    def add_school(self, school_name):
        self.school = school_name
        self.save()



